package cn.myjerry.test.reflection;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import cn.myjerry.test.reflection.bean.User;

public class Demo05 {
	
	public void test01(Map<String, User> map, List<User> list) {
		System.out.println("Demo05.test01()");
	}
	
	public Map<Integer, User> test02(){
		System.out.println("Demo05.test02()");
		return null;
	}
	
	public static void main(String[] args) throws Exception {
		// 获得指定方法参数泛型信息
		Method m = Demo05.class.getMethod("test01", Map.class, List.class);
		Type[] t = m.getGenericParameterTypes();
		for(Type parameterType:t) {
			System.out.println("# " + parameterType);
			if(parameterType instanceof ParameterizedType) {
				Type[] genericTypes =  ((ParameterizedType) parameterType).getActualTypeArguments();
				for(Type genericType:genericTypes) {
					System.out.println("泛型类型：" + genericType);
				}
			}
		}
		
		Method m2 = Demo05.class.getMethod("test02", null);
		Type returnType = m2.getGenericReturnType();
		if(returnType instanceof ParameterizedType) {
			Type[] genericTypes =  ((ParameterizedType) returnType).getActualTypeArguments();
			for(Type genericType:genericTypes) {
				System.out.println("返回值，泛型类型：" + genericType);
			}
		}

	}
}
